use std::collections::HashMap;

use axum::{response::IntoResponse, Json, Router};

pub fn greeting_router() -> Router {
    Router::new().merge(greeting1()).merge(greeting2())
}

// api
fn greeting1() -> Router {
    async fn handler(
        Json(_): Json<HashMap<String, String>>,
    ) -> Result<Json<HashMap<String, String>>, crate::error::Error> {
        let mut h = HashMap::new();
        h.insert("name".to_string(), "hades".to_string());
        Ok(Json::from(h))
    }

    Router::new().route("/greeting1", axum::routing::post(handler))
}

fn greeting2() -> Router {
    async fn handler() -> Result<impl IntoResponse, crate::error::Error> {
        Ok("hello greeting2")
    }

    Router::new().route("/greeting2", axum::routing::post(handler))
}
